package com.photoeditor.demo.model.image.emoji;

import android.content.Context;
import android.content.res.Resources;

import com.common.base.ComponentContext;
import com.photoeditor.R;
import com.photoeditor.demo.model.share.ShareImageTools;

/**
 * 需要安装的Emoji Resource 和 InstalledStickerResource的区别就是没有长宽那些字段所有那种字段都是默认的
 */
public class InstalledEmojiResource extends StickerApkResource{

    //google play的下载地址
    private String mDownloadUrl;

    public InstalledEmojiResource(Context context, String pkgName, String googlePlayUrl) {
        super(pkgName);
        mDownloadUrl = googlePlayUrl;
        init(context);
    }

    @Override
    public void init(Context context) {
        //初始化外置安装Apk的信息
        if(ShareImageTools.getAppIsInstalled(context, mPkgName)){
            Context mApkContext = null;
            try {
                mApkContext = context.createPackageContext(mPkgName, Context.CONTEXT_IGNORE_SECURITY);
                if(mApkContext != null){
                    isExist = true;
                    mRes = mApkContext.getResources();
                    setInit(true);
                    setName(StickerConstant.APK_EMOJI_NAME);
                    int id = mRes.getIdentifier("emoji_name", "array", mPkgName);
                    setEmojiNames(mRes.getStringArray(id));
                    mEmojiColNum = StickerConstant.DEFAULT_COL_NUM;
                    mEmojiPageNum = StickerConstant.DEFAULT_PAGE_EMOJI_NUM;
                    Resources contextRes = context.getResources();
                    mVerticalSpacing = contextRes.getDimensionPixelSize(R.dimen.image_edit_emoji_item_margin);
                    mEmojiWidth = contextRes.getDimensionPixelSize(R.dimen.image_edit_emoji_item_size);
                    mEmojiHeight = mEmojiWidth;
                    mItemWidth = contextRes.getDimensionPixelSize(R.dimen.default_button_size);
                    mItemHeight = mItemWidth;
                    mPageHeight = contextRes.getDimensionPixelSize(R.dimen.image_edit_grid_height);
                    mEditEmojiWidth = contextRes.getDimensionPixelSize(R.dimen.image_edit_emoji_default_size);
                    mEditEmojiHeight = contextRes.getDimensionPixelSize(R.dimen.image_edit_emoji_default_size);
                    mNeedBuy = false;
                    mAlreadyBuy = false;
                    mStickerIconId = 0;
                    setBgColor(ComponentContext.getContext().getResources().getColor(R.color.emoji_pannel_default_background_color));
                }
            } catch (Throwable e) {
                e.printStackTrace();
                isExist = false;
            }

        } else{
            isExist = false;
        }
    }

    public String getDownloadUrl() {
        return mDownloadUrl;
    }

    public void setDownloadUrl(String mDownloadUrl) {
        this.mDownloadUrl = mDownloadUrl;
    }
}
